repo: Move the transaction stats to a separate struct
authorJasper St. Pierre <jstpierre@mecheye.net>
Thu, 5 Sep 2013 20:48:40 +0000 (16:48 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Sat, 7 Sep 2013 00:31:12 +0000 (20:31 -0400)
This is much easier for callers to handle, and simplifies
the API a lot.

https://bugzilla.gnome.org/show_bug.cgi?id=707644

doc/ostree-sections.txt
src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo-private.h
src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo.h
src/ostree/ot-builtin-commit.c
src/ostree/ot-builtin-pull-local.c

index 34a2faf389a5d7d023184c2a9cff739ae57634e5..f5abbd57460981a3ae9f7c8d4e63b1531f736914 100644 (file)
@@ -63,9 +63,9 @@ ostree_repo_get_config
 ostree_repo_copy_config
 ostree_repo_get_parent
 ostree_repo_write_config
+OstreeRepoTransactionStats
 ostree_repo_prepare_transaction
 ostree_repo_commit_transaction
-ostree_repo_commit_transaction_with_stats
 ostree_repo_abort_transaction
 ostree_repo_has_object
 ostree_repo_write_metadata
index 39b75faf5c91025204f4cc5323301bc4b46261bb..69b48c8fcafb841d5ff7ee586b2da41413aaed02 100644 (file)
@@ -367,18 +367,18 @@ write_object (OstreeRepo         *self,
     {
       if (OSTREE_OBJECT_TYPE_IS_META (objtype))
         {
-          self->txn_metadata_objects_written++;
+          self->txn_stats.metadata_objects_written++;
         }
       else
         {
-          self->txn_content_objects_written++;
-          self->txn_content_bytes_written += file_object_length;
+          self->txn_stats.content_objects_written++;
+          self->txn_stats.content_bytes_written += file_object_length;
         }
     }
   if (OSTREE_OBJECT_TYPE_IS_META (objtype))
-    self->txn_metadata_objects_total++;
+    self->txn_stats.metadata_objects_total++;
   else
-    self->txn_content_objects_total++;
+    self->txn_stats.content_objects_total++;
   g_mutex_unlock (&self->txn_stats_lock);
 
   if (checksum)
@@ -562,11 +562,7 @@ ostree_repo_prepare_transaction (OstreeRepo     *self,
   else
     ret_transaction_resume = FALSE;
 
-  self->txn_metadata_objects_total =
-    self->txn_metadata_objects_written =
-    self->txn_content_objects_total =
-    self->txn_content_objects_written =
-    self->txn_content_bytes_written = 0;
+  memset (&self->txn_stats, 0, sizeof (OstreeRepoTransactionStats));
 
   self->in_transaction = TRUE;
   if (ret_transaction_resume)
@@ -631,14 +627,10 @@ cleanup_tmpdir (OstreeRepo        *self,
 }
 
 gboolean
-ostree_repo_commit_transaction_with_stats (OstreeRepo     *self,
-                                           guint          *out_metadata_objects_total,
-                                           guint          *out_metadata_objects_written,
-                                           guint          *out_content_objects_total,
-                                           guint          *out_content_objects_written,
-                                           guint64        *out_content_bytes_written,
-                                           GCancellable   *cancellable,
-                                           GError        **error)
+ostree_repo_commit_transaction (OstreeRepo                  *self,
+                                OstreeRepoTransactionStats  *out_stats,
+                                GCancellable                *cancellable,
+                                GError                     **error)
 {
   gboolean ret = FALSE;
 
@@ -655,26 +647,14 @@ ostree_repo_commit_transaction_with_stats (OstreeRepo     *self,
   if (!ot_gfile_ensure_unlinked (self->transaction_lock_path, cancellable, error))
     goto out;
 
-  if (out_metadata_objects_total) *out_metadata_objects_total = self->txn_metadata_objects_total;
-  if (out_metadata_objects_written) *out_metadata_objects_written = self->txn_metadata_objects_written;
-  if (out_content_objects_total) *out_content_objects_total = self->txn_content_objects_total;
-  if (out_content_objects_written) *out_content_objects_written = self->txn_content_objects_written;
-  if (out_content_bytes_written) *out_content_bytes_written = self->txn_content_bytes_written;
+  if (out_stats)
+    *out_stats = self->txn_stats;
 
   ret = TRUE;
  out:
   return ret;
 }
 
-gboolean
-ostree_repo_commit_transaction (OstreeRepo     *self,
-                                GCancellable   *cancellable,
-                                GError        **error)
-{
-  return ostree_repo_commit_transaction_with_stats (self, NULL, NULL, NULL, NULL, NULL,
-                                                    cancellable, error);
-}
-
 gboolean
 ostree_repo_abort_transaction (OstreeRepo     *self,
                                GCancellable   *cancellable,
@@ -1622,3 +1602,19 @@ ostree_repo_commit_modifier_unref (OstreeRepoCommitModifier *modifier)
 G_DEFINE_BOXED_TYPE(OstreeRepoCommitModifier, ostree_repo_commit_modifier,
                     ostree_repo_commit_modifier_ref,
                     ostree_repo_commit_modifier_unref);
+
+static OstreeRepoTransactionStats *
+ostree_repo_transaction_stats_copy (OstreeRepoTransactionStats *stats)
+{
+  return g_memdup (stats, sizeof (OstreeRepoTransactionStats));
+}
+
+static void
+ostree_repo_transaction_stats_free (OstreeRepoTransactionStats *stats)
+{
+  return g_free (stats);
+}
+
+G_DEFINE_BOXED_TYPE(OstreeRepoTransactionStats, ostree_repo_transaction_stats,
+                    ostree_repo_transaction_stats_copy,
+                    ostree_repo_transaction_stats_free);
index ed7daae28e5994460f4c70b546bb785d2bc56df4..383ea50eee4d5bee6d884975de45d2cad6d77134 100644 (file)
@@ -40,11 +40,7 @@ struct OstreeRepo {
 
   GFile *transaction_lock_path;
   GMutex txn_stats_lock;
-  guint txn_metadata_objects_total;
-  guint txn_metadata_objects_written;
-  guint txn_content_objects_total;
-  guint txn_content_objects_written;
-  guint64 txn_content_bytes_written;
+  OstreeRepoTransactionStats txn_stats;
 
   GMutex cache_lock;
   GPtrArray *cached_meta_indexes;
index bdb1958fa829fc22fb684c6953b05f93a4de4f70..0a42e3f9c6ec47e1a21a866cef584351465d5134 100644 (file)
@@ -1332,7 +1332,7 @@ ostree_repo_pull (OstreeRepo               *self,
   if (!run_mainloop_monitor_fetcher (pull_data))
     goto out;
   
-  if (!ostree_repo_commit_transaction (pull_data->repo, cancellable, error))
+  if (!ostree_repo_commit_transaction (pull_data->repo, NULL, cancellable, error))
     goto out;
 
   g_hash_table_iter_init (&hash_iter, updated_refs);
index 186b4804610fdcd96b0d89d3717e92fd2bbeb8c1..882e3061b7f2cf08410b29bee5839257e1a4a592 100644 (file)
@@ -79,24 +79,49 @@ gboolean      ostree_repo_write_config (OstreeRepo *self,
                                         GKeyFile   *new_config,
                                         GError    **error);
 
+/**
+ * OstreeRepoTransactionStats:
+ * @metadata_objects_total: The total number of metadata objects
+ * in the repository after this transaction has completed.
+ * @metadata_objects_written: The number of metadata objects that
+ * were written to the repository in this transaction.
+ * @content_objects_total: The total number of content objects
+ * in the repository after this transaction has completed.
+ * @content_objects_written: The number of content objects that
+ * were written to the repository in this transaction.
+ * @content_bytes_total: The amount of data added to the repository,
+ * in bytes, counting only content objects.
+ *
+ * A list of statistics for each transaction that may be
+ * interesting for reporting purposes.
+ */
+typedef struct _OstreeRepoTransactionStats OstreeRepoTransactionStats;
+
+struct _OstreeRepoTransactionStats {
+  guint metadata_objects_total;
+  guint metadata_objects_written;
+  guint content_objects_total;
+  guint content_objects_written;
+  guint64 content_bytes_written;
+
+  guint64 padding1;
+  guint64 padding2;
+  guint64 padding3;
+  guint64 padding4;
+};
+
+GType ostree_repo_transaction_stats_get_type (void);
+
 gboolean      ostree_repo_prepare_transaction (OstreeRepo     *self,
                                                gboolean        enable_commit_hardlink_scan,
                                                gboolean       *out_transaction_resume,
                                                GCancellable   *cancellable,
                                                GError        **error);
 
-gboolean      ostree_repo_commit_transaction (OstreeRepo     *self,
-                                              GCancellable   *cancellable,
-                                              GError        **error);
-
-gboolean      ostree_repo_commit_transaction_with_stats (OstreeRepo     *self,
-                                                         guint          *out_metadata_objects_total,
-                                                         guint          *out_metadata_objects_written,
-                                                         guint          *out_content_objects_total,
-                                                         guint          *out_content_objects_written,
-                                                         guint64        *out_content_bytes_written,
-                                                         GCancellable   *cancellable,
-                                                         GError        **error);
+gboolean      ostree_repo_commit_transaction (OstreeRepo                  *self,
+                                              OstreeRepoTransactionStats  *out_stats,
+                                              GCancellable                *cancellable,
+                                              GError                     **error);
 
 gboolean      ostree_repo_abort_transaction (OstreeRepo     *self,
                                              GCancellable   *cancellable,
index 7ef203774d27e3f2aa5c09ed4faa4e5170d00ec2..22d6d89c2c18fc9a3fc558a2da69c9397937c615 100644 (file)
@@ -225,11 +225,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   gboolean ret = FALSE;
   gboolean skip_commit = FALSE;
   gboolean in_transaction = FALSE;
-  guint metadata_total = 0;
-  guint metadata_written = 0;
-  guint content_total = 0;
-  guint content_written = 0;
-  guint64 content_bytes_written = 0;
   gs_unref_object GFile *arg = NULL;
   gs_free char *parent = NULL;
   gs_free char *commit_checksum = NULL;
@@ -243,6 +238,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   gs_free char *parent_content_checksum = NULL;
   gs_free char *parent_metadata_checksum = NULL;
   OstreeRepoCommitModifier *modifier = NULL;
+  OstreeRepoTransactionStats stats;
 
   context = g_option_context_new ("[ARG] - Commit a new revision");
   g_option_context_add_main_entries (context, options, NULL);
@@ -424,13 +420,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
                                      &commit_checksum, cancellable, error))
         goto out;
 
-      if (!ostree_repo_commit_transaction_with_stats (repo,
-                                                      &metadata_total,
-                                                      &metadata_written,
-                                                      &content_total,
-                                                      &content_written,
-                                                      &content_bytes_written,
-                                                      cancellable, error))
+      if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error))
         goto out;
 
       in_transaction = FALSE;
@@ -452,11 +442,11 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   if (opt_table_output)
     {
       g_print ("Commit: %s\n", commit_checksum);
-      g_print ("Metadata Total: %u\n", metadata_total);
-      g_print ("Metadata Written: %u\n", metadata_written);
-      g_print ("Content Total: %u\n", content_total);
-      g_print ("Content Written: %u\n", content_written);
-      g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", content_bytes_written);
+      g_print ("Metadata Total: %u\n", stats.metadata_objects_total);
+      g_print ("Metadata Written: %u\n", stats.metadata_objects_written);
+      g_print ("Content Total: %u\n", stats.content_objects_total);
+      g_print ("Content Written: %u\n", stats.content_objects_written);
+      g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", stats.content_bytes_written);
     }
   else
     {
index b7749e16e75f587cbdf157b999c9e99d8e9cdafe..98ba6cd2cb47c8cfff305bd57403c2a4d95cba5c 100644 (file)
@@ -290,7 +290,7 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable
         gs_console_end_status_line (data->console, NULL, NULL);
     }
 
-  if (!ostree_repo_commit_transaction (data->dest_repo, NULL, error))
+  if (!ostree_repo_commit_transaction (data->dest_repo, NULL, NULL, error))
     goto out;
 
   g_print ("Writing %u refs\n", g_hash_table_size (refs_to_clone));